



package view.jfreechartTest;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.labels.XYToolTipGenerator;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.chart.urls.StandardXYURLGenerator;
import org.jfree.chart.urls.XYURLGenerator;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

import view.DrawXYFromDatabase;

import demo.SampleXYDataset2;

// Referenced classes of package demo:
//            SampleXYDataset2

public class ScatterPlotDemo1 extends ApplicationFrame
{
	private static TimeSeriesCollection dataset;

    public static TimeSeriesCollection getDataset() {
		return dataset;
	}

	public static void setDataset(TimeSeriesCollection dataset) {
		ScatterPlotDemo1.dataset = dataset;
	}

	public ScatterPlotDemo1(String s, TimeSeriesCollection dataset)
    {
        super(s);
        this.dataset = dataset;
        JPanel jpanel = createDemoPanel(s);
        jpanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(jpanel);
    }

    private static JFreeChart createChart(String chartName)
    {
        JFreeChart jfreechart = ChartFactorySupply.createScatterDatePlot(chartName, "日期", "金额", dataset, PlotOrientation.VERTICAL, true, false, false);
        XYPlot plot = (XYPlot)jfreechart.getPlot();
        
        plot.setNoDataMessage("NO DATA");
        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();
        xylineandshaperenderer.setSeriesOutlinePaint(0, Color.black);
        xylineandshaperenderer.setUseOutlinePaint(true);
        
        //设置中文
        ValueAxis domainAxis = plot.getDomainAxis();
		ValueAxis numberaxis = plot.getRangeAxis(); 
		LegendTitle legend = jfreechart.getLegend();

		TextTitle t = jfreechart.getTitle();
		t.setFont(new Font("宋体", Font.BOLD, 40));// 标题文字
		jfreechart.setBackgroundPaint(Color.gray);
		domainAxis.setLabelFont(new Font("宋体", Font.BOLD, 20));// x轴标题
		domainAxis.setTickLabelFont(new Font("黑体", Font.BOLD, 10));// x轴坐标上文字
		numberaxis.setLabelFont(new Font("宋体", Font.BOLD, 20));// y轴标题
		numberaxis.setTickLabelFont(new Font("黑体", Font.BOLD, 10));// y轴坐标上文字
		legend.setItemFont(new Font("黑体", Font.BOLD, 11));// 图例文字
		
        return jfreechart;
    }

    public static JPanel createDemoPanel(String chartName)
    {
        JFreeChart jfreechart = createChart(chartName);
        ChartPanel chartpanel = new ChartPanel(jfreechart);
        chartpanel.setVerticalAxisTrace(true);
        chartpanel.setHorizontalAxisTrace(true);
        chartpanel.setPopupMenu(null);
        chartpanel.setDomainZoomable(true);
        chartpanel.setRangeZoomable(true);
        return chartpanel;
    }


    
//    private static TimeSeriesCollection createDataset(int query)
//    {
//    	
//    	//TODO: 根据query判断viewName
//    	String id = "5088010010000000783";
//    	String viewName = "";
//    	if(query%2 == 0){                     //deposit(recharge)柱状图
//    		viewName = "merge_recharge";
//		}
//		else if(query%5 == 0) {               //posPay
//			viewName = "merge_pospay";
//		}
//		else {  
//			viewName = "merge_onlinepay";
//		}
//    	//return DrawXYFromDatabase.drawXYPlotFromResultSet(id);
//    	return DrawXYFromDatabase.drawXYPlotFromViewSet(viewName,"消费金额");
//    	
//    }
    
    public static void main(String args[])
    {
//        ScatterPlotDemo1 scatterplotdemo1 = new ScatterPlotDemo1("Scatter Plot Demo 1",3);
//        scatterplotdemo1.pack();
//        RefineryUtilities.centerFrameOnScreen(scatterplotdemo1);
//        scatterplotdemo1.setVisible(true);
    }
}
